# encoding: utf-8
import imp
import sys
imp.reload(sys)
from traceback import print_tb
import matplotlib.pyplot as plt;
import numpy as np;
import pandas as pd

data=pd.read_table("/home/student/桌面/HW2/B.txt",sep=',',header=None)
m=-1
j=0
x=[[0]*9 for i in range(4)]
f=[[0]*9 for i in range(4)]
for i in range(len(data[0])):
    if(data[0][i]==-5):
        m=m+1
        j=0
    x[m][j]=data[0][i]
    f[m][j]=data[1][i]
    j=j+1
X=np.array(x[m])
Y=1/(X*X+1)
xx=np.arange(-5,5,0.0001)
y = 1/(xx*xx+1)
plt.figure()
for i in range(1,5):
    p=f[0][0]
    for j in range(1,2*i+1):
        s=1
        for l in range(j):
            s=s*(xx-x[i-1][l])
        p=p+f[i-1][j]*s
    plt.plot(xx,p)
plt.plot(xx,y,'--')
plt.scatter(X,Y)
plt.title("the Runge phenomenon of B")
plt.savefig("B.png")
